import 'dart:typed_data';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:image_save/image_save.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();
  final MethodChannel channel = MethodChannel('image_save');
  late Uint8List _data;

  setUp(() {
    // 使用本地测试数据而不是从网络加载
    _data = Uint8List.fromList([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]); // PNG文件头
    
    // 设置MethodChannel的mock处理程序
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      switch (methodCall.method) {
        case 'saveImage':
          return true;
        case 'saveImageToSandbox':
          return true;
        case 'getImagesFromSandbox':
          return [_data];
        default:
          return null;
      }
    });
  });

  tearDown(() {
    channel.setMockMethodCallHandler(null);
  });

  test('saveImage', () async {
    expect(await ImageSave.saveImage(_data, "test.gif", albumName: "demo"), isTrue);
  });

  test('saveImageToSandbox', () async {
    expect(await ImageSave.saveImageToSandbox(_data, "test.gif"), isTrue);
  });

  test('getImagesFromSandbox', () async {
    expect(await ImageSave.getImagesFromSandbox(), isNotNull);
  });
}
